<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="单据号" prop="serialNo">
        <el-input
          v-model="queryParams.serialNo"
          placeholder="请输入单据号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户" prop="customerId">
        <el-select v-model="queryParams.customerId" placeholder="请选择客户" clearable filterable size="small">
          <el-option
            v-for="dict in customerIdOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="申请人" prop="applyUser">
        <el-select v-model="queryParams.applyUser" placeholder="请选择申请人" clearable filterable size="small">
          <el-option
            v-for="dict in applyUserOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="申请日期" prop="applyTime">
        <el-date-picker clearable size="small"
                        v-model="queryParams.applyTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择申请日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="申请状态" prop="applyStatus">
        <el-select v-model="queryParams.applyStatus" placeholder="请选择申请状态" clearable filterable size="small">
          <el-option
            v-for="dict in applyStatusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审核人" prop="auditUser">
        <el-select v-model="queryParams.auditUser" placeholder="请选择审核人" clearable filterable size="small">
          <el-option
            v-for="dict in auditUserOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审核日期" prop="auditTime">
        <el-date-picker clearable size="small"
                        v-model="queryParams.auditTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择审核日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="审核状态" prop="auditStatus">
        <el-select v-model="queryParams.auditStatus" placeholder="请选择审核状态" clearable filterable size="small">
          <el-option
            v-for="dict in auditStatusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="出库单号" prop="outWarehouseId">
        <el-input
          v-model="queryParams.outWarehouseId"
          placeholder="请输入出库单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发货单号" prop="saleDeliveryNo">
        <el-input
          v-model="queryParams.saleDeliveryNo"
          placeholder="请输入发货单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['wms:carrierApply:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['wms:carrierApply:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['wms:carrierApply:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['wms:carrierApply:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="carrierApplyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="编号" align="center" prop="id"/>
      <el-table-column label="单据号" align="center" prop="serialNo" show-overflow-tooltip/>
      <el-table-column label="出库单号" align="center" prop="outWarehouseId" :formatter="outWarehouseIdFormat"
                       show-overflow-tooltip
      />
      <el-table-column label="客户" align="center" prop="customerId" :formatter="customerIdFormat"
                       show-overflow-tooltip
      />
      <el-table-column label="收货地址" align="center" prop="shippingAddress" show-overflow-tooltip/>

      <el-table-column label="联系人" align="center" prop="contact" show-overflow-tooltip/>
      <el-table-column label="联系电话" align="center" prop="contactTel" show-overflow-tooltip/>
      <el-table-column label="承运人" align="center" prop="carrierUser" :formatter="carrierUserFormat"
                       show-overflow-tooltip
      />
      <el-table-column label="交货日期" align="center" prop="deliveryDate" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deliveryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="运输距离" align="center" prop="distance" show-overflow-tooltip/>
      <el-table-column label="申请人" align="center" prop="applyUser" :formatter="applyUserFormat"
                       show-overflow-tooltip
      />
      <el-table-column label="申请日期" align="center" prop="applyTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="申请状态" align="center" prop="applyStatus" :formatter="applyStatusFormat"
                       show-overflow-tooltip
      />
      <el-table-column label="审核人" align="center" prop="auditUser" :formatter="auditUserFormat"
                       show-overflow-tooltip
      />
      <el-table-column label="审核日期" align="center" prop="auditTime" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.auditTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="auditStatus" :formatter="auditStatusFormat"
                       show-overflow-tooltip
      />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['wms:carrierApply:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['wms:carrierApply:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改产品承运申请对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" :inline="true">
        <el-form-item label="单据号" prop="serialNo">
          <el-input v-model="form.serialNo" placeholder="请输入单据号"/>
        </el-form-item>
        <el-form-item label="出库单号" prop="outWarehouseId">
          <el-select v-model="form.outWarehouseId" placeholder="请选择出库单号" clearable filterable size="small">
            <el-option
              v-for="dict in outWarehouseIdOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="发货单号" prop="saleDeliveryNo">
          <el-select v-model="form.saleDeliveryNo" placeholder="请选择发货单号" clearable filterable size="small">
            <el-option
              v-for="dict in saleDeliveryIdOption"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="客户" prop="customerId">
          <el-select v-model="form.customerId" placeholder="请选择客户" clearable filterable size="small">
            <el-option
              v-for="dict in customerIdOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="交货日期" prop="deliveryDate">
          <el-date-picker clearable size="small"
                          v-model="form.deliveryDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择交货日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="收货地址" prop="shippingAddress">
          <el-input v-model="form.shippingAddress" placeholder="请输入收货地址"/>
        </el-form-item>
        <el-form-item label="联系人" prop="contact">
          <el-input v-model="form.contact" placeholder="请输入联系人"/>
        </el-form-item>
        <el-form-item label="联系电话" prop="contactTel">
          <el-input v-model="form.contactTel" placeholder="请输入联系电话"/>
        </el-form-item>
        <el-form-item label="承运人" prop="carrierUser">
          <el-select v-model="form.carrierUser" placeholder="请选择承运人" clearable filterable size="small">
            <el-option
              v-for="dict in carrierUserOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="运输距离" prop="distance">
          <el-input v-model="form.distance" placeholder="请输入运输距离"/>
        </el-form-item>
        <el-form-item label="申请人" prop="applyUser">
          <el-select v-model="form.applyUser" placeholder="请选择申请人" clearable filterable size="small">
            <el-option
              v-for="dict in applyUserOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="申请日期" prop="applyTime">
          <el-date-picker clearable size="small"
                          v-model="form.applyTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择申请日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="申请状态" prop="applyStatus">
          <el-select v-model="form.applyStatus" placeholder="请选择申请状态" clearable filterable size="small">
            <el-option
              v-for="dict in applyStatusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="审核人" prop="auditUser">
          <el-select v-model="form.auditUser" placeholder="请选择审核人" clearable filterable size="small">
            <el-option
              v-for="dict in auditUserOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="审核日期" prop="auditTime">
          <el-date-picker clearable size="small"
                          v-model="form.auditTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择审核日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审核状态" prop="auditStatus">
          <el-select v-model="form.auditStatus" placeholder="请选择审核状态" clearable filterable size="small">
            <el-option
              v-for="dict in auditStatusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注"/>
        </el-form-item>
        <el-divider content-position="center">产品承运申请明细信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddWmsCarrierApplyDetail">添加
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteWmsCarrierApplyDetail">删除
            </el-button>
          </el-col>
        </el-row>
        <el-table :data="wmsCarrierApplyDetailList" :row-class-name="rowWmsCarrierApplyDetailIndex"
                  @selection-change="handleWmsCarrierApplyDetailSelectionChange" ref="wmsCarrierApplyDetail"
        >
          <el-table-column type="selection" width="50" align="center"/>
          <el-table-column label="序号" align="center" prop="index" width="50"/>
          <el-table-column label="物料" prop="materialId" width="150">
            <template slot-scope="scope">
              <el-form-item :prop="'wmsCarrierApplyDetailList.'+scope.$index+'.materialId'" :rules="rules.materialId">
                <el-select v-model="scope.row.materialId" placeholder="请选择物料" clearable filterable size="small">
                  <el-option
                    v-for="dict in materialIdOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  />
                </el-select>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="生产批号" prop="batchNo" width="150">
            <template slot-scope="scope">
              <el-form-item :prop="'wmsCarrierApplyDetailList.'+scope.$index+'.batchNo'" :rules="rules.batchNo">
                <el-input v-model="scope.row.batchNo" placeholder="请输入生产批号"/>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="仓库" prop="warehouseId" width="150">
            <template slot-scope="scope">
              <el-form-item :prop="'wmsCarrierApplyDetailList.'+scope.$index+'.warehouseId'" :rules="rules.warehouseId">
                <el-select v-model="scope.row.warehouseId" placeholder="请选择仓库" clearable filterable size="small">
                  <el-option
                    v-for="dict in warehouseIdOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  />
                </el-select>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="库区" prop="whRegionId" width="150">
            <template slot-scope="scope">
              <el-form-item :prop="'wmsCarrierApplyDetailList.'+scope.$index+'.whRegionId'" :rules="rules.whRegionId">
                <el-select v-model="scope.row.whRegionId" placeholder="请选择库区" clearable filterable size="small">
                  <el-option
                    v-for="dict in whRegionIdOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  />
                </el-select>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="库位" prop="whLocationId" width="150">
            <template slot-scope="scope">
              <el-form-item :prop="'wmsCarrierApplyDetailList.'+scope.$index+'.whLocationId'"
                            :rules="rules.whLocationId"
              >
                <el-select v-model="scope.row.whLocationId" placeholder="请选择库位" clearable filterable size="small">
                  <el-option
                    v-for="dict in whLocationIdOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  />
                </el-select>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="发货数量" prop="deliveryQuantity" width="150">
            <template slot-scope="scope">
              <el-form-item :prop="'wmsCarrierApplyDetailList.'+scope.$index+'.deliveryQuantity'"
                            :rules="rules.deliveryQuantity"
              >
                <el-input v-model="scope.row.deliveryQuantity" placeholder="请输入发货数量"/>
              </el-form-item>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  addCarrierApply,
  delCarrierApply,
  exportCarrierApply,
  getCarrierApply,
  listCarrierApply,
  updateCarrierApply
} from '@/api/wms/carrierApply'
import { parseTime } from '../../../utils/neu'

export default {
  name: 'CarrierApply',
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedWmsCarrierApplyDetail: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品承运申请表格数据
      carrierApplyList: [],
      // 产品承运申请明细表格数据
      wmsCarrierApplyDetailList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 客户字典
      customerIdOptions: [],
      // 申请人字典
      applyUserOptions: [],
      // 申请状态字典
      applyStatusOptions: [],
      // 审核人字典
      auditUserOptions: [],
      // 审核状态字典
      auditStatusOptions: [],
      // 出库单号字典
      outWarehouseIdOptions: [],
      // 承运人字典
      carrierUserOptions: [],
      // 物料字典
      materialIdOptions: [],
      // 仓库字典
      warehouseIdOptions: [],
      // 库区字典
      whRegionIdOptions: [],
      // 库位字典
      whLocationIdOptions: [],
      // 发货单字典
      saleDeliveryIdOption: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        serialNo: null,
        customerId: null,
        applyUser: null,
        applyTime: null,
        applyStatus: null,
        auditUser: null,
        auditTime: null,
        auditStatus: null,
        outWarehouseId: null,
        saleDeliveryNo: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        customerId: [
          { required: true, message: '客户不能为空', trigger: 'change' }
        ],
        shippingAddress: [
          { required: true, message: '收货地址不能为空', trigger: 'blur' }
        ],
        contact: [
          { required: true, message: '联系人不能为空', trigger: 'blur' }
        ],
        contactTel: [
          { required: true, message: '联系电话不能为空', trigger: 'blur' }
        ],
        carrierUser: [
          { required: true, message: '承运人不能为空', trigger: 'change' }
        ],
        distance: [
          { required: true, message: '运输距离不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getList()
    this.getQueryData('query_customer').then(res => {
      this.customerIdOptions = res.data
    })
    this.getQueryData('query_user').then(res => {
      this.applyUserOptions = res.data
    })
    this.getDicts('apply_status').then(response => {
      this.applyStatusOptions = response.data
    })
    this.getQueryData('query_user').then(res => {
      this.auditUserOptions = res.data
    })
    this.getDicts('audit_status').then(response => {
      this.auditStatusOptions = response.data
    })
    this.getQueryData('query_out_warehouse_apply').then(res => {
      this.outWarehouseIdOptions = res.data
    })
    this.getQueryData('query_user').then(res => {
      this.carrierUserOptions = res.data
    })
    this.getQueryData('query_material').then(res => {
      this.materialIdOptions = res.data
    })
    this.getQueryData('query_warehouse').then(res => {
      this.warehouseIdOptions = res.data
    })
    this.getQueryData('query_warehouse_region').then(res => {
      this.whRegionIdOptions = res.data
    })
    this.getQueryData('query_warehouse_location').then(res => {
      this.whLocationIdOptions = res.data
    })
    this.getQueryData('query_sale_delivery').then(res => {
      this.saleDeliveryIdOption = res.data
    })
  },
  watch: {
    'wmsCarrierApplyDetailList': {
      handler(newVal, oldVal) {
        this.form.wmsCarrierApplyDetailList = newVal
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    parseTime,
    /** 查询产品承运申请列表 */
    getList() {
      this.loading = true
      listCarrierApply(this.queryParams).then(response => {
        this.carrierApplyList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 客户字典翻译
    customerIdFormat(row, column) {
      return this.selectDictLabel(this.customerIdOptions, row.customerId)
    },
    // 申请人字典翻译
    applyUserFormat(row, column) {
      return this.selectDictLabel(this.applyUserOptions, row.applyUser)
    },
    // 申请状态字典翻译
    applyStatusFormat(row, column) {
      return this.selectDictLabel(this.applyStatusOptions, row.applyStatus)
    },
    // 审核人字典翻译
    auditUserFormat(row, column) {
      return this.selectDictLabel(this.auditUserOptions, row.auditUser)
    },
    // 审核状态字典翻译
    auditStatusFormat(row, column) {
      return this.selectDictLabel(this.auditStatusOptions, row.auditStatus)
    },
    // 出库单号字典翻译
    outWarehouseIdFormat(row, column) {
      return this.selectDictLabel(this.outWarehouseIdOptions, row.outWarehouseId)
    },
    // 承运人字典翻译
    carrierUserFormat(row, column) {
      return this.selectDictLabel(this.carrierUserOptions, row.carrierUser)
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        serialNo: null,
        customerId: null,
        applyUser: null,
        applyTime: null,
        applyStatus: null,
        auditUser: null,
        auditTime: null,
        auditStatus: null,
        outWarehouseId: null,
        outWarehouseNo: null,
        saleDeliveryId: null,
        saleDeliveryNo: null,
        shippingAddress: null,
        contact: null,
        contactTel: null,
        carrierUser: null,
        distance: null,
        remark: null,
        auditComment: null,
        deliveryDate: null,
        wmsCarrierApplyDetailList: []
      }
      this.wmsCarrierApplyDetailList = []
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加产品承运申请'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getCarrierApply(id).then(response => {
        this.form = response.data
        this.wmsCarrierApplyDetailList = response.data.wmsCarrierApplyDetailList
        this.open = true
        this.title = '修改产品承运申请'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {

          if (this.form.id != null) {
            updateCarrierApply(this.form).then(response => {
              this.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addCarrierApply(this.form).then(response => {
              this.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$confirm('是否确认删除产品承运申请编号为"' + ids + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return delCarrierApply(ids)
      }).then(() => {
        this.getList()
        this.msgSuccess('删除成功')
      })
    },
    /** 产品承运申请明细序号 */
    rowWmsCarrierApplyDetailIndex({ row, rowIndex }) {
      row.index = rowIndex + 1
    },
    /** 产品承运申请明细添加按钮操作 */
    handleAddWmsCarrierApplyDetail() {
      let obj = {}
      this.wmsCarrierApplyDetailList.push(obj)
    },
    /** 产品承运申请明细删除按钮操作 */
    handleDeleteWmsCarrierApplyDetail() {
      if (this.checkedWmsCarrierApplyDetail.length == 0) {
        this.$alert('请先选择要删除的产品承运申请明细数据', '提示', { confirmButtonText: '确定' })
      } else {
        this.wmsCarrierApplyDetailList.splice(this.checkedWmsCarrierApplyDetail[0].index - 1, 1)
      }
    },
    /** 单选框选中数据 */
    handleWmsCarrierApplyDetailSelectionChange(selection) {
      if (selection.length > 1) {
        this.$refs.wmsCarrierApplyDetail.clearSelection()
        this.$refs.wmsCarrierApplyDetail.toggleRowSelection(selection.pop())
      } else {
        this.checkedWmsCarrierApplyDetail = selection
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams
      this.$confirm('是否确认导出所有产品承运申请数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return exportCarrierApply(queryParams)
      }).then(response => {
        this.download(response.msg)
      })
    }
  }
}
</script>
